package com.contacts.alipayplugin;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.contacts.paystander.PayInterfaceBroadcast;

import java.lang.reflect.Constructor;

/**
 * 插桩
 * Created by zuo on 2018/4/22.
 */
public class ProxyBroadCast extends BroadcastReceiver {
    private String className;
    private PayInterfaceBroadcast mPayInterfaceBroadcast;

    public ProxyBroadCast(String className,Context context) {
        this.className = className;
        try {
            Class loadClass = PluginManager.getInstance().getDexClassLoader().loadClass(className);
            Constructor constructor = loadClass.getConstructor(new Class[]{});
            Object instance= constructor.newInstance(new Object[]{});
            mPayInterfaceBroadcast = (PayInterfaceBroadcast)instance;
            mPayInterfaceBroadcast.attach(context);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        mPayInterfaceBroadcast.onReceive(context,intent);
    }
}
